Technical Q&A

TB45 - Calling GetMenu Redundantly (17-December-98)


Q: Why does Inside Macintosh warn about calling GetMenu only once for a particular menu? I've done this before (by accident), and testing with the usual stress tools and in the field turns up no problems.

A: GetMenu loads the 'MENU' resource, uses the menu definition function resource ('MDEF') ID to load the proper 'MDEF', and then stores the handle to the 'MDEF' inside the MenuHandle.

In the original (64K) ROMs [which are present only in the Mac 128 and 512], the problem was that GetMenu would not check to see if the menu had been previously loaded, and would assume that the high byte of the 'MENU' record held the ID of the 'MDEF' to load; in fact, it actually held the high byte of the handle to the 'MDEF'.

This problem was fixed in the 128K ROMs (Mac Plus and 512Ke) and all subsequent systems. Unless your application needs to run on a 128K or 512K Macintosh (unlikely in this day and age), it's safe to call GetMenu repeatedly.

Finally, although it's safe today, it's probably not advisable over the long run. Future versions of the Mac OS API may do such things as return to your application a new handle based on the resource template, not just a modified resource handle. So, when you get a chance, do revise your code to avoid calling GetMenu redundantly, even though it won't crash you today.

Further Reference:

Inside Macintosh: Menu Manager


-- Pete Gontier
Worldwide Developer Technical Support

Technical Q&As | Contents
Previous Question | Next Question

To contact us, please use the Contact Us page.